//
//  WNavigationBar.m
//  WProjectForNative
//
//  Created by huangzhen on 16/9/11.
//  Copyright © 2016年 huangzhen. All rights reserved.
//

#import "WNavigationBar.h"
#import "UIImage+Color.h"
#import "UIViewController+TopViewController.h"
#import "UtilsMacro.h"
#import <ReactiveCocoa.h>
#import "UIView+Layout.h"
@interface WNavigationBar()
@property (nonatomic, strong) UILabel *titleLable;
@end

@implementation WNavigationBar
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:CGRectMake(0, 0, ScreenWidth, NavBarHeight)];
    if (self) {
        self.translucent = NO;
        self.tintColor = RGB(255, 255, 255);
        self.barTintColor = kNavBlueColor;
        self.shadowImage = [[UIImage alloc]init];
        self.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],
                                     NSFontAttributeName:[UIFont systemFontOfSize:18]};
        [self setBackgroundImage:[UIImage imageWithSolidColor:kNavBlueColor size:CGSizeMake(1, 1)]
                   forBarMetrics:UIBarMetricsDefault];
        [self addSubview:self.backButton];
    }
    return self;
}

- (void)setTitle:(NSString *)title {
    _title = title;
    UINavigationItem *item = [[UINavigationItem alloc]initWithTitle:title];
    self.items = @[item];
}

- (void)setCenterCustomView:(UIView *)centerCustomView {
    _centerCustomView = centerCustomView;
    [self addSubview:centerCustomView];
    centerCustomView.centerX = ScreenWidth/2;
}

- (void)setRightCustomView:(UIView *)rightCustomView {
    _rightCustomView = rightCustomView;
    [self addSubview:rightCustomView];
    rightCustomView.centerY = NavBarHeight/2+10;
    rightCustomView.left = ScreenWidth - rightCustomView.width;
}
-(void)setLeftCustomView:(UIView *)leftCustomView {
    
    _leftCustomView = leftCustomView;
    if (leftCustomView) {
        self.backButton.hidden = YES;
    }else {
        self.backButton.hidden = NO;
    }
    
    [self addSubview:leftCustomView];
    leftCustomView.centerY = NavBarHeight/2+10;
    leftCustomView.left = 0;
}

- (UIButton *)backButton {
    if (!_backButton) {
        _backButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 20, 44, 44)];
        [_backButton setImage:[UIImage imageNamed:@"icon_white_back"] forState:UIControlStateNormal];
    }
    return _backButton;
}


@end
